﻿/*
 * FaceCat图形通讯框架
 * 著作权编号:2015SR229355+2020SR0266727
 * 上海卷卷猫信息技术有限公司
 */

using System;
using System.Collections.Generic;
using System.Text;

namespace FaceCat {
    /// <summary>
    /// 字符串处理类
    /// </summary>
    public class FCTran {
        /// <summary>
        /// 锚定信息转化为字符
        /// </summary>
        /// <param name="anchor"> 锚定信息</param>
        /// <returns>字符</returns>
        public static String anchorToStr(FCAnchor anchor) {
            ArrayList<String> strs = new ArrayList<String>();
            if (anchor.left) {
                strs.add("Left");
            }
            if (anchor.top) {
                strs.add("Top");
            }
            if (anchor.right) {
                strs.add("Right");
            }
            if (anchor.bottom) {
                strs.add("Bottom");
            }
            String anchorStr = "";
            int size = strs.size();
            if (size > 0) {
                for (int i = 0; i < size; i++) {
                    anchorStr += strs[i];
                    if (i != size - 1) {
                        anchorStr += ",";
                    }
                }
            }
            else {
                anchorStr = "None";
            }
            return anchorStr;
        }

        /// <summary>
        /// 布尔型数值转换为字符
        /// </summary>
        /// <param name="value">数值</param>
        /// <returns>字符</returns>
        public static String boolToStr(bool value) {
            return value ? "True" : "False";
        }

        /// <summary>
        /// 颜色转换为字符
        /// </summary>
        /// <param name="color">颜色</param>
        /// <returns>字符</returns>
        public static String colorToStr(long color)
        {
            switch (color)
            {
                case FCColor.None:
                    return "None";
                case FCColor.Back:
                    return "Back";
                case FCColor.Border:
                    return "Border";
                case FCColor.Text:
                    return "Text";
                case FCColor.DisabledBack:
                    return "DisabledBack";
                case FCColor.DisabledText:
                    return "DisabledText";
                default:
                    {
                        if (color < FCColor.None)
                        {
                            return FCTran.longToStr(color);
                        }
                        else
                        {
                            int a = 0, r = 0, g = 0, b = 0;
                            FCColor.toRgba(null, color, ref r, ref g, ref b, ref a);
                            String str = String.Empty;
                            if (a == 255)
                            {
                                str = String.Format("rgb({0},{1},{2})", r, g, b);
                            }
                            else
                            {
                                str = String.Format("rgba({0},{1},{2},{3})", r, g, b, a);
                            }
                            return str;
                        }
                    }
            }
        }

        /// <summary>
        /// 内容布局转字符串
        /// </summary>
        /// <param name="contentAlignment">内容布局</param>
        /// <returns>字符串</returns>
        public static String contentAlignmentToStr(FCContentAlignment contentAlignment)
        {
            String str = "";
            switch (contentAlignment)
            {
                case FCContentAlignment.BottomCenter:
                    {
                        str = "BottomCenter";
                        break;
                    }
                case FCContentAlignment.BottomLeft:
                    {
                        str = "BottomLeft";
                        break;
                    }
                case FCContentAlignment.BottomRight:
                    {
                        str = "BottomRight";
                        break;
                    }
                case FCContentAlignment.MiddleCenter:
                    {
                        str = "MiddleCenter";
                        break;
                    }
                case FCContentAlignment.MiddleLeft:
                    {
                        str = "MiddleLeft";
                        break;
                    }
                case FCContentAlignment.MiddleRight:
                    {
                        str = "MiddleRight";
                        break;
                    }
                case FCContentAlignment.TopCenter:
                    {
                        str = "TopCenter";
                        break;
                    }
                case FCContentAlignment.TopLeft:
                    {
                        str = "TopLeft";
                        break;
                    }
                case FCContentAlignment.TopRight:
                    {
                        str = "TopRight";
                        break;
                    }
            }
            return str;
        }

        /// <summary>
        /// 光标转换为字符
        /// </summary>
        /// <param name="cursor">光标</param>
        /// <returns>字符</returns>
        public static String cursorToStr(FCCursors cursor)
        {
            String str = "";
            switch (cursor)
            {
                case FCCursors.AppStarting:
                    {
                        str = "AppStarting";
                        break;
                    }
                case FCCursors.Arrow:
                    {
                        str = "Arrow";
                        break;
                    }
                case FCCursors.Cross:
                    {
                        str = "Cross";
                        break;
                    }
                case FCCursors.Hand:
                    {
                        str = "Hand";
                        break;
                    }
                case FCCursors.Help:
                    {
                        str = "Help";
                        break;
                    }
                case FCCursors.IBeam:
                    {
                        str = "IBeam";
                        break;
                    }
                case FCCursors.No:
                    {
                        str = "NO";
                        break;
                    }
                case FCCursors.SizeAll:
                    {
                        str = "SizeAll";
                        break;
                    }
                case FCCursors.SizeNESW:
                    {
                        str = "SizeNESW";
                        break;
                    }
                case FCCursors.SizeNS:
                    {
                        str = "SizeNS";
                        break;
                    }
                case FCCursors.SizeNWSE:
                    {
                        str = "SizeNWSE";
                        break;
                    }
                case FCCursors.SizeWE:
                    {
                        str = "SizeWE";
                        break;
                    }
                case FCCursors.UpArrow:
                    {
                        str = "UpArrow";
                        break;
                    }
                case FCCursors.WaitCursor:
                    {
                        str = "WaitCursor";
                        break;
                    }
            }
            return str;
        }


        /// <summary>
        /// 将日期格式转换为数字格式
        /// </summary>
        /// <param name="date">日期</param>
        /// <returns>数字格式</returns>
        public static double dateToNum(DateTime date) {
            return FCTran.getDateNum(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Millisecond);
        }

        /// <summary>
        /// 绑定信息转换为字符
        /// </summary>
        /// <param name="dock">绑定信息</param>
        /// <returns>字符</returns>
        public static String dockToStr(FCDockStyle dock)
        {
            String str = "";
            switch (dock)
            {
                case FCDockStyle.Bottom:
                    {
                        str = "Bottom";
                        break;
                    }
                case FCDockStyle.Fill:
                    {
                        str = "Fill";
                        break;
                    }
                case FCDockStyle.Left:
                    {
                        str = "Left";
                        break;
                    }
                case FCDockStyle.None:
                    {
                        str = "None";
                        break;
                    }
                case FCDockStyle.Right:
                    {
                        str = "Right";
                        break;
                    }
                case FCDockStyle.Top:
                    {
                        str = "Top";
                        break;
                    }
            }
            return str;
        }

        /// <summary>
        /// 双精度浮点型数值转换为字符
        /// </summary>
        /// <param name="value">数值</param>
        /// <returns>字符</returns>
        public static String doubleToStr(double value) {
            return value.ToString();
        }

        /// <summary>
        /// 单精度浮动点型数值转换为字符
        /// </summary>
        /// <param name="value">数值</param>
        /// <returns>字符</returns>
        public static String floatToStr(float value) {
            return value.ToString();
        }

        /// <summary>
        /// 字体转换为字符
        /// </summary>
        /// <param name="font">字体</param>
        /// <returns>字符</returns>
        public static String fontToStr(FCFont font) {
            ArrayList<String> strs = new ArrayList<String>();
            strs.add(font.m_fontFamily);
            strs.add(getValueByDigit(font.m_fontSize, 1));
            if (font.m_bold) {
                strs.add("Bold");
            }
            if (font.m_underline) {
                strs.add("UnderLine");
            }
            if (font.m_italic) {
                strs.add("Italic");
            }
            if (font.m_strikeout) {
                strs.add("Strikeout");
            }
            if (font.m_angle != 0)
            {
                strs.add("Angle=" + intToStr(font.m_angle));
            }
            String fontStr = "";
            int size = strs.size();
            if (size > 0) {
                for (int i = 0; i < size; i++) {
                    fontStr += strs[i];
                    if (i != size - 1) {
                        fontStr += ",";
                    }
                }
            }
            return fontStr;
        }

        /// <summary>
        /// 横向排列方式转换为字符
        /// </summary>
        /// <param name="horizontalAlign">横向排列方式</param>
        /// <returns>字符</returns>
        public static String horizontalAlignToStr(FCHorizontalAlign horizontalAlign)
        {
            String str = "";
            switch (horizontalAlign)
            {
                case FCHorizontalAlign.Center:
                    {
                        str = "Center";
                        break;
                    }
                case FCHorizontalAlign.Right:
                    {
                        str = "Right";
                        break;
                    }
                case FCHorizontalAlign.Inherit:
                    {
                        str = "Inherit";
                        break;
                    }
                case FCHorizontalAlign.Left:
                    {
                        str = "Left";
                        break;
                    }
            }
            return str;
        }

        /// <summary>
        /// 整型数值转换为字符
        /// </summary>
        /// <param name="value">数值</param>
        /// <returns>字符</returns>
        public static String intToStr(int value) {
            return value.ToString();
        }

        /// <summary>
        /// 布局样式转换为字符
        /// </summary>
        /// <param name="layoutStyle">布局样式转</param>
        /// <returns>布局样式</returns>
        public static String layoutStyleToStr(FCLayoutStyle layoutStyle)
        {
            String str = "";
            switch (layoutStyle)
            {
                case FCLayoutStyle.BottomToTop:
                    {
                        str = "BottomToTop";
                        break;
                    }
                case FCLayoutStyle.LeftToRight:
                    {
                        str = "LeftToRight";
                        break;
                    }
                case FCLayoutStyle.None:
                    {
                        str = "None";
                        break;
                    }
                case FCLayoutStyle.RightToLeft:
                    {
                        str = "RightToLeft";
                        break;
                    }
                case FCLayoutStyle.TopToBottom:
                    {
                        str = "TopToBottom";
                        break;
                    }
            }
            return str;
        }

        /// <summary>
        /// 长整型数值转换为字符
        /// </summary>
        /// <param name="value">数值</param>
        /// <returns>字符串</returns>
        public static String longToStr(long value) {
            return value.ToString();
        }

        /// <summary>
        /// 将数字格式转换为日期格式
        /// </summary>
        /// <param name="num">数字</param>
        /// <returns>日期格式</returns>
        public static DateTime numToDate(double num) {
            int tm_year = 0;
            int tm_mon = 0;
            int tm_mday = 0;
            int tm_hour = 0;
            int tm_min = 0;
            int tm_sec = 0;
            int tm_msec = 0;
            FCTran.getDateByNum(num, ref tm_year, ref tm_mon, ref tm_mday, ref tm_hour, ref tm_min, ref tm_sec, ref tm_msec);
            return new DateTime(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_msec);
        }

        /// <summary>
        /// 边距转换为字符
        /// </summary>
        /// <param name="padding">边距</param>
        /// <returns>字符</returns>
        public static String paddingToStr(FCPadding padding) {
            return String.Format("{0},{1},{2},{3}", padding.left, padding.top, padding.right, padding.bottom);
        }

        /// <summary>
        /// 坐标转换为字符
        /// </summary>
        /// <param name="point">坐标</param>
        /// <returns>字符</returns>
        public static String pointToStr(FCPoint point) {
            return String.Format("{0},{1}", point.x, point.y);
        }

        /// <summary>
        /// 矩形转换为字符
        /// </summary>
        /// <param name="rect">矩形</param>
        /// <returns>字符</returns>
        public static String rectToStr(FCRect rect) {
            return String.Format("{0},{1},{2},{3}", rect.left, rect.top, rect.right, rect.bottom);
        }

        /// <summary>
        /// 大小转换为字符
        /// </summary>
        /// <param name="size">大小</param>
        /// <returns>字符</returns>
        public static String sizeToStr(FCSize size) {
            return String.Format("{0},{1}", size.cx, size.cy);
        }

        /// <summary>
        /// 字符转换为锚定信息
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>锚定信息</returns>
        public static FCAnchor strToAnchor(String str)
        {
            str = str.ToLower();
            bool left = false, top = false, right = false, bottom = false;
            String[] strs = str.Split(',');
            for (int i = 0; i < strs.Length; i++)
            {
                String anchorStr = strs[i];
                switch (anchorStr)
                {
                    case "left":
                        {
                            left = true;
                            break;
                        }
                    case "top":
                        {
                            top = true;
                            break;
                        }
                    case "right":
                        {
                            right = true;
                            break;
                        }
                    case "bottom":
                        {
                            bottom = true;
                            break;
                        }
                }
            }
            FCAnchor anchor = new FCAnchor(left, top, right, bottom);
            return anchor;
        }

        /// <summary>
        /// 字符转换为布尔型
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>数值</returns>
        public static bool strToBool(String str) {
            str = str.ToLower();
            return str == "true" ? true : false;
        }

        /// <summary>
        /// Html颜色
        /// </summary>
        public static HashMap<String, String> m_htmlColors = new HashMap<String, String>();

        /// <summary>
        /// 字符转换为颜色
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>颜色</returns>
        public static long strToColor(String str)
        {
            str = str.ToLower();
            switch (str)
            {
                case "none":
                    {
                        return FCColor.None;
                    }
                case "back":
                    {
                        return FCColor.Back;
                    }
                case "border":
                    {
                        return FCColor.Border;
                    }
                case "text":
                    {
                        return FCColor.Text;
                    }
                case "disabledback":
                    {
                        return FCColor.DisabledBack;
                    }
                case "disabledtext":
                    {
                        return FCColor.DisabledText;
                    }
                default:
                    {
                        if (str.IndexOf("rgba(") == 0)
                        {
                            String strColor = str.Substring(5, str.Length - 6);
                            String[] strs = strColor.Split(',');
                            int a = 255, r = 255, g = 255, b = 255;
                            int.TryParse(strs[0], out r);
                            int.TryParse(strs[1], out g);
                            int.TryParse(strs[2], out b);
                            int.TryParse(strs[3], out a);
                            return FCColor.rgba(r, g, b, a);
                        }
                        else if (str.IndexOf("rgb(") == 0)
                        {
                            String strColor = str.Substring(4, str.Length - 5);
                            String[] strs = strColor.Split(',');
                            int r = 255, g = 255, b = 255;
                            int.TryParse(strs[0], out r);
                            int.TryParse(strs[1], out g);
                            int.TryParse(strs[2], out b);
                            return FCColor.rgb(r, g, b);
                        }
                        else
                        {
                            return FCTran.strToLong(str);
                        }
                    }
            }
        }

        /// <summary>
        /// 字符串转内容布局
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>字符串</returns>
        public static FCContentAlignment strToContentAlignment(String str)
        {
            str = str.ToLower();
            FCContentAlignment contentAlignment = FCContentAlignment.MiddleCenter;
            switch (str)
            {
                case "bottomcenter":
                    {
                        contentAlignment = FCContentAlignment.BottomCenter;
                        break;
                    }
                case "bottomleft":
                    {
                        contentAlignment = FCContentAlignment.BottomLeft;
                        break;
                    }
                case "bottomright":
                    {
                        contentAlignment = FCContentAlignment.BottomRight;
                        break;
                    }
                case "middlecenter":
                    {
                        contentAlignment = FCContentAlignment.MiddleCenter;
                        break;
                    }
                case "middleleft":
                    {
                        contentAlignment = FCContentAlignment.MiddleLeft;
                        break;
                    }
                case "middleright":
                    {
                        contentAlignment = FCContentAlignment.MiddleRight;
                        break;
                    }
                case "topcenter":
                    {
                        contentAlignment = FCContentAlignment.TopCenter;
                        break;
                    }
                case "topleft":
                    {
                        contentAlignment = FCContentAlignment.TopLeft;
                        break;
                    }
                case "topright":
                    {
                        contentAlignment = FCContentAlignment.TopRight;
                        break;
                    }
            }
            return contentAlignment;
        }

        /// <summary>
        /// 字符转换为光标
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>光标</returns>
        public static FCCursors strToCursor(String str)
        {
            str = str.ToLower();
            FCCursors cursor = FCCursors.Arrow;
            switch (str)
            {
                case "appstarting":
                    {
                        cursor = FCCursors.AppStarting;
                        break;
                    }
                case "cross":
                    {
                        cursor = FCCursors.Cross;
                        break;
                    }
                case "hand":
                    {
                        cursor = FCCursors.Hand;
                        break;
                    }
                case "help":
                    {
                        cursor = FCCursors.Help;
                        break;
                    }
                case "ibeam":
                    {
                        cursor = FCCursors.IBeam;
                        break;
                    }
                case "no":
                    {
                        cursor = FCCursors.No;
                        break;
                    }
                case "sizeall":
                    {
                        cursor = FCCursors.SizeAll;
                        break;
                    }
                case "sizenesw":
                    {
                        cursor = FCCursors.SizeNESW;
                        break;
                    }
                case "sizens":
                    {
                        cursor = FCCursors.SizeNS;
                        break;
                    }
                case "sizenwse":
                    {
                        cursor = FCCursors.SizeNWSE;
                        break;
                    }
                case "sizewe":
                    {
                        cursor = FCCursors.SizeWE;
                        break;
                    }
                case "uparrow":
                    {
                        cursor = FCCursors.UpArrow;
                        break;
                    }
                case "waitcursor":
                    {
                        cursor = FCCursors.WaitCursor;
                        break;
                    }
            }
            return cursor;
        }

        /// <summary>
        /// 字符转换为绑定信息
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>绑定信息</returns>
        public static FCDockStyle strToDock(String str)
        {
            str = str.ToLower();
            FCDockStyle dock = FCDockStyle.None;
            switch (str)
            {
                case "bottom":
                    {
                        dock = FCDockStyle.Bottom;
                        break;
                    }
                case "fill":
                    {
                        dock = FCDockStyle.Fill;
                        break;
                    }
                case "left":
                    {
                        dock = FCDockStyle.Left;
                        break;
                    }
                case "right":
                    {
                        dock = FCDockStyle.Right;
                        break;
                    }
                case "top":
                    {
                        dock = FCDockStyle.Top;
                        break;
                    }
            }
            return dock;
        }

        /// <summary>
        /// 字符转换为双精度浮点型数值
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>数值</returns>
        public static double strToDouble(String str) {
            double value = 0;
            double.TryParse(str, out value);
            return value;
        }

        /// <summary>
        /// 字符转换为单精度浮点型数值
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>数值</returns>
        public static float strToFloat(String str) {
            float value = 0;
            float.TryParse(str, out value);
            return value;
        }

        /// <summary>
        /// 字符转换为字体
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>字体</returns>
        public static FCFont strToFont(String str) {
            String[] strs = str.Split(',');
            int size = strs.Length;
            String fontFamily = "Default";
            float fontSize = 12;
            bool bold = false;
            bool underline = false;
            bool italic = false;
            bool strikeout = false;
            int angle = 0;
            if (size >= 1) {
                fontFamily = strs[0];
            }
            if (size >= 2) {
                float.TryParse(strs[1], out fontSize);
            }
            for (int i = 2; i < size; i++)
            {
                String subStr = strs[i].ToLower();
                switch (subStr)
                {
                    case "bold":
                        {
                            bold = true;
                            break;
                        }
                    case "underline":
                        {
                            underline = true;
                            break;
                        }
                    case "italic":
                        {
                            italic = true;
                            break;
                        }
                    case "strikeout":
                        {
                            strikeout = true;
                            break;
                        }
                    default:
                        {
                            if (subStr.IndexOf("angle=") == 0)
                            {
                                angle = FCTran.strToInt(subStr.Substring(6));
                            }
                            break;
                        }
                }
            }
            FCFont font = new FCFont(fontFamily, fontSize, bold, underline, italic, strikeout);
            font.m_angle = angle;
            return font;
        }

        /// <summary>
        /// 字符转换为横向排列方式
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>字符</returns>
        public static FCHorizontalAlign strToHorizontalAlign(String str)
        {
            str = str.ToLower();
            FCHorizontalAlign horizontalAlign = FCHorizontalAlign.Center;
            switch (str)
            {
                case "right":
                    {
                        horizontalAlign = FCHorizontalAlign.Right;
                        break;
                    }
                case "inherit":
                    {
                        horizontalAlign = FCHorizontalAlign.Inherit;
                        break;
                    }
                case "left":
                    {
                        horizontalAlign = FCHorizontalAlign.Left;
                        break;
                    }
            }
            return horizontalAlign;
        }

        /// <summary>
        /// 字符转换为整型数值
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>数值</returns>
        public static int strToInt(String str) {
            int value = 0;
            int.TryParse(str, out value);
            return value;
        }

        /// <summary>
        /// 布局样式转换为字符
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>布局样式</returns>
        public static FCLayoutStyle strToLayoutStyle(String str)
        {
            str = str.ToLower();
            FCLayoutStyle layoutStyle = FCLayoutStyle.None;
            switch (str)
            {
                case "bottomtotop":
                    {
                        layoutStyle = FCLayoutStyle.BottomToTop;
                        break;
                    }
                case "lefttoright":
                    {
                        layoutStyle = FCLayoutStyle.LeftToRight;
                        break;
                    }
                case "righttoleft":
                    {
                        layoutStyle = FCLayoutStyle.RightToLeft;
                        break;
                    }
                case "toptobottom":
                    {
                        layoutStyle = FCLayoutStyle.TopToBottom;
                        break;
                    }
            }
            return layoutStyle;
        }

        /// <summary>
        /// 字符转换位长整型数值
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns>长整型</returns>
        public static long strToLong(String str) {
            long value = 0;
            long.TryParse(str, out value);
            return value;
        }

        /// <summary>
        /// 字符转换为边距
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>边距</returns>
        public static FCPadding strToPadding(String str) {
            int left = 0, top = 0, right = 0, bottom = 0;
            if (str.IndexOf(",") != -1)
            {
                String[] strs = str.Split(',');
                if (strs.Length == 4)
                {
                    int.TryParse(strs[0], out left);
                    int.TryParse(strs[1], out top);
                    int.TryParse(strs[2], out right);
                    int.TryParse(strs[3], out bottom);
                }
            }
            else if (str.IndexOf(" ") != -1)
            {
                String[] strs = str.Split(' ');
                if (strs.Length == 4)
                {
                    int.TryParse(strs[0], out left);
                    int.TryParse(strs[1], out top);
                    int.TryParse(strs[2], out right);
                    int.TryParse(strs[3], out bottom);
                }
            }
            return new FCPadding(left, top, right, bottom);
        }

        /// <summary>
        /// 字符转换为坐标
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>坐标</returns>
        public static FCPoint strToPoint(String str) {
            int x = 0, y = 0;
            if (str.IndexOf(",") != -1)
            {
                String[] strs = str.Split(',');
                if (strs.Length == 2)
                {
                    int.TryParse(strs[0], out x);
                    int.TryParse(strs[1], out y);
                }
            }
            else if (str.IndexOf(" ") != -1)
            {
                String[] strs = str.Split(' ');
                if (strs.Length == 2)
                {
                    int.TryParse(strs[0], out x);
                    int.TryParse(strs[1], out y);
                }
            }
            return new FCPoint(x, y);
        }

        /// <summary>
        /// 字符转换为矩形
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>矩形</returns>
        public static FCRect strToRect(String str) {
            int left = 0, top = 0, right = 0, bottom = 0;
            if (str.IndexOf(",") != -1)
            {
                String[] strs = str.Split(',');
                if (strs.Length == 4)
                {
                    int.TryParse(strs[0], out left);
                    int.TryParse(strs[1], out top);
                    int.TryParse(strs[2], out right);
                    int.TryParse(strs[3], out bottom);
                }
            }
            else if (str.IndexOf(" ") != -1)
            {
                String[] strs = str.Split(' ');
                if (strs.Length == 4)
                {
                    int.TryParse(strs[0], out left);
                    int.TryParse(strs[1], out top);
                    int.TryParse(strs[2], out right);
                    int.TryParse(strs[3], out bottom);
                }
            }
            return new FCRect(left, top, right, bottom);
        }

        /// <summary>
        /// 字符转换为大小
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>大小</returns>
        public static FCSize strToSize(String str) {
            int cx = 0, cy = 0;
            if (str.IndexOf(",") != -1)
            {
                String[] strs = str.Split(',');
                if (strs.Length == 2)
                {
                    int.TryParse(strs[0], out cx);
                    int.TryParse(strs[1], out cy);
                }
            }
            else if (str.IndexOf(" ") != -1)
            {
                String[] strs = str.Split(' ');
                if (strs.Length == 2)
                {
                    int.TryParse(strs[0], out cx);
                    int.TryParse(strs[1], out cy);
                }
            }
            return new FCSize(cx, cy);
        }

        /// <summary>
        /// 字符转换为纵向排列方式
        /// </summary>
        /// <param name="str">字符</param>
        /// <returns>字符</returns>
        public static FCVerticalAlign strToVerticalAlign(String str)
        {
            str = str.ToLower();
            FCVerticalAlign verticalAlign = FCVerticalAlign.Middle;
            switch (str)
            {
                case "bottom":
                    {
                        verticalAlign = FCVerticalAlign.Bottom;
                        break;
                    }
                case "inherit":
                    {
                        verticalAlign = FCVerticalAlign.Inherit;
                        break;
                    }
                case "top":
                    {
                        verticalAlign = FCVerticalAlign.Top;
                        break;
                    }
            }
            return verticalAlign;
        }

        /// <summary>
        /// 纵向排列方式转换为字符
        /// </summary>
        /// <param name="verticalAlign">横向排列方式</param>
        /// <returns>字符</returns>
        public static String verticalAlignToStr(FCVerticalAlign verticalAlign)
        {
            String str = "";
            switch (verticalAlign)
            {
                case FCVerticalAlign.Bottom:
                    {
                        str = "Bottom";
                        break;
                    }
                case FCVerticalAlign.Inherit:
                    {
                        str = "Inherit";
                        break;
                    }
                case FCVerticalAlign.Middle:
                    {
                        str = "Middle";
                        break;
                    }
                case FCVerticalAlign.Top:
                    {
                        str = "Top";
                        break;
                    }
            }
            return str;
        }

        /// <summary>
        /// 获取日期的数值
        /// </summary>
        public static double getDateNum(int tm_year, int tm_mon, int tm_mday, int tm_hour, int tm_min, int tm_sec, int tm_msec) {
            return (new DateTime(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec) - new DateTime(1970, 1, 1)).TotalSeconds;
        }

        /// <summary>
        /// 根据日期数值获取年月日时分秒
        /// </summary>
        public static void getDateByNum(double num, ref int tm_year, ref int tm_mon, ref int tm_mday, ref int tm_hour, ref int tm_min, ref int tm_sec, ref int tm_msec) {
            DateTime date = new DateTime(new DateTime(1970, 1, 1).Ticks + (long)num * 10000000);
            tm_year = date.Year;
            tm_mon = date.Month;
            tm_mday = date.Day;
            tm_hour = date.Hour;
            tm_min = date.Minute;
            tm_sec = date.Second;
        }

        /// <summary>
        /// 获取Guid
        /// </summary>
        /// <returns>Guid</returns>
        public static String getGuid() {
            return Guid.NewGuid().ToString();
        }

        /*格式化字符串*/
        private const String FORMATSTRING_N = "0";
        private const String FORMATSTRING_N1 = "0.0";
        private const String FORMATSTRING_N2 = "0.00";
        private const String FORMATSTRING_N3 = "0.000";
        private const String FORMATSTRING_N4 = "0.0000";

        /// <summary>
        /// 根据保留小数的位置将double型转化为String型
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="digit">保留小数点</param>
        /// <returns>数值字符</returns>
        public static String getValueByDigit(double value, int digit) {
            //保留超过4位时
            if (digit > 4) {
                StringBuilder format = new StringBuilder();
                format.Append("0");
                if (digit > 0) {
                    format.Append(".");
                    for (int i = 0; i < digit; i++) {
                        format.Append("0");
                    }
                }
                return value.ToString(format.ToString());
            }
            else {
                //4位及以下
                switch (digit) {
                    case 1:
                        return value.ToString(FORMATSTRING_N1);
                    case 2:
                        return value.ToString(FORMATSTRING_N2);
                    case 3:
                        return value.ToString(FORMATSTRING_N3);
                    case 4:
                        return value.ToString(FORMATSTRING_N4);
                    default:
                        return value.ToString(FORMATSTRING_N);
                }
            }
        }

        /// <summary>
        /// 安全的Double转Float
        /// </summary>
        /// <param name="value">数值</param>
        /// <param name="digit">保留小数位数</param>
        /// <returns>Float</returns>
        public static float safeDoubleToFloat(double value, int digit) {
            String str = getValueByDigit(value, digit);
            return strToFloat(str);
        }
    }
}